package cn.zc.examination.service.service.impl;

import cn.tools.core.exception.BizException;
import cn.zc.examination.entity.Dto.ExaminationClassifyAndBankDto;
import cn.zc.examination.entity.ExaminationClassifyAndBank;
import cn.zc.examination.service.mapper.ExaminationClassifyAndBankMapper;
import cn.zc.examination.service.service.ExaminationClassifyAndBankService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 考试类别对应题库表 服务实现类
 * </p>
 *
 * @author keno
 * @since 2022-02-22
 */
@Service
public class ExaminationClassifyAndBankServiceImpl extends ServiceImpl<ExaminationClassifyAndBankMapper, ExaminationClassifyAndBank> implements ExaminationClassifyAndBankService {
    @Resource
    private ExaminationClassifyAndBankMapper examinationClassifyAndBankMapper;

    /**
     * 创建类目对应题
     * @param examinationClassifyAndBankDto
     */
    @Override
    public void createExaminationClassifyAndBank(ExaminationClassifyAndBankDto examinationClassifyAndBankDto) {
        List<ExaminationClassifyAndBank> list = new ArrayList<>();
        for(String backId:examinationClassifyAndBankDto.getExaminationBankId()){
            ExaminationClassifyAndBank examinationClassifyAndBank = new ExaminationClassifyAndBank();
            examinationClassifyAndBank.setExaminationBankId(backId);
            examinationClassifyAndBank.setExaminationClassifyId(examinationClassifyAndBankDto.getExaminationClassifyId());
            list.add(examinationClassifyAndBank);
        }
        if(!saveBatch(list)){
            throw new BizException("创建考试与对应题失败");
        };
    }
}
